<template>
	<view class="page">
		<view class="nav-style"
			:style="{ height: navHeight - 15 + 'px', 'padding-top': 15 + 'px', lineHeight: navHeight + 'px', fontWeight: 600, fontSize: 18 + 'px' }">
			<image style="width: 40rpx; height: 40rpx" src="/static/image/back.png" mode="aspectFit" @click="back">
			</image>
			<span style="display: inline-block; position: absolute; left: 100rpx" @click="skip">列表</span>
			商业性性伴志愿者
		</view>

		<view v-if="!show">
			<view style="background-color: #f4f6f8; padding: 12px 15px">
				<view class="content" :style="{ marginTop: navHeight + 'px' }">
					<!-- 南昌问卷组件 -->
					<NanchangQuestionnaire v-if="TypeHide" @subWenjuanEven='subWenjuanEven'></NanchangQuestionnaire>

					<view v-if="!TypeHide">
						<view class="one">
							<text class="label">性别</text>
							<uni-data-checkbox v-model="Info.Sex" :localdata="sex"></uni-data-checkbox>
						</view>
						<view class="one">
							<text class="label">年龄</text>
							<uni-data-picker v-model="Info.Age" :localdata="age" placeholder=""></uni-data-picker>
						</view>
						<view class="one">
							<text class="label">确证时间</text>
							<uni-datetime-picker :border="false" type="date" placeholder="请选择确证时间"
								v-model="Info.DiagnoseTime" :end="currentDate" />
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">近6个月是否有无保护性行为</text>
							<uni-data-checkbox v-model="Info.UnprotectAction"
								:localdata="wbhOptions"></uni-data-checkbox>
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">近6个月是否有商业性性行为</text>
							<uni-data-checkbox v-model="Info.DangerAction" :localdata="syOptions"></uni-data-checkbox>
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">是否感染过梅毒、淋病等性传播疾病</text>
							<uni-data-checkbox v-model="Info.InfectIllness" :localdata="cbOptions"></uni-data-checkbox>
						</view>
						<view class="one">
							<text class="label">可能的感染途径</text>
							<uni-data-picker v-model="Info.InfectionMode" :localdata="grtj"
								placeholder=""></uni-data-picker>
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">性伴数(近六个月)</text>
							<uni-easyinput v-model="Info.SexQuantity" type="number" placeholder="请输入性伴数" />
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">首次CD4</text>
							<uni-easyinput v-model="Info.FirstCD4" type="number" placeholder="请输入首次CD4" />
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">首次病毒载量</text>
							<uni-easyinput v-model="Info.FirstVL" type="number" placeholder="请输入首次病毒载量" />
						</view>
						<view class="one">
							<text class="label" style="width: 250rpx">新发感染检测结果</text>
							<uni-data-checkbox v-model="Info.NewResult" :localdata="resOptions"></uni-data-checkbox>
						</view>
						<view class="one">
							<text style="color: red">*</text>
							<text class="label" style="width: 250rpx">是否愿意为性伴提供自检试剂</text>
							<uni-data-checkbox v-model="Info.Inclination" :localdata="tgOptions"></uni-data-checkbox>
						</view>
						<view class="one" v-if="Info.Inclination == '是'">
							<text style="color: red">*</text>
							<text class="label" style="width: 250rpx">提供自检试剂日期</text>
							<uni-datetime-picker :border="false" type="date" placeholder="请选择提供自检试剂日期"
								v-model="Info.ObtainTime" :end="currentDate" />
						</view>

						<view class="one" style="margin-top: 10rpx; height: 200rpx" v-if="Info.Inclination == '是'">
							<view style="height: 200rpx">
								<text style="color: red">*</text>
								<text class="label" style="width: 250rpx">提供的自检试剂编号</text>
							</view>
							<view style="height: 200rpx">
								<view style="display: flex; align-items: center; margin-bottom: 20rpx"
									v-for="item in deviceList" :key="item">
									<view
										style="display: inline-block; padding: 10rpx; background-color: #e9f8f7; margin-right: 10rpx; border-radius: 10rpx">
										{{ item }}
									</view>
									<uni-icons type="close" size="24" color="#c7c1bc"
										@click="removeOne(item)"></uni-icons>
								</view>
							</view>
							<view class="icon">
								<view @click="addOne" style="margin-left: 20rpx; margin-top: 20rpx">
									<uni-icons type="plus" size="24" color="#E10000"></uni-icons>
								</view>
								<view @click="sys" style="margin-left: 20rpx; margin-top: 60rpx">
									<image src="/static/image/sys.png" mode=""></image>
								</view>
							</view>
						</view>
						<view class="one" v-if="Info.Inclination == '是'">
							<view>
								<text style="color: red">*</text>
								<text class="label" style="width: 250rpx">提供自检试剂数量</text>
							</view>
							<text>{{ devNum ? devNum : '' }}</text>
						</view>

						<view style="height: 100%">
							<view style="display: flex; width: 300rpx; justify-content: space-between">
								<text style="color: red">*</text>
								<text style="color: #222222; font-weight: 500; font-size: 28rpx">地址和商业类型</text>
							</view>
							<view class="" v-for="(item, index) in AddressArr" :key="index"
								style="border-bottom: 1rpx solid gray; padding-bottom: 10rpx">
								<view class="" style="width: 100%; display: flex; justify-content: space-around">
									<uni-easyinput v-model="item.address" placeholder="请打开地图选择性交易位置"
										style="width: 50%" />
									<button @click="chooseLocation(index)"
										style="height:70rpx;width: 18%; font-size: 25rpx; margin-left: 10rpx; background-color: #3791ff; color: #e9f8f7">
										地图
									</button>
								</view>
								<view style="width: 100%; position: relative">
									<uni-data-picker v-model="item.categor" :localdata="Addressmap"
										placeholder="请选择商业类型"></uni-data-picker>
									<button
										style="position: absolute; top: 0; right: 0; width: 18%; font-size: 25rpx; background-color: coral; color: #e9f8f7"
										@click="removeAddress(index)">
										删除
									</button>
								</view>
							</view>
							<button
								style="width: 100%; font-size: 25rpx; background-color: #3791ff; color: #e9f8f7; margin-top: 20rpx"
								@click="addAddress">新增地址和商业类型</button>
						</view>

					</view>


				</view>
				<view class="btn-box" style="width: 85%; margin: 0 auto" v-if="!TypeHide">
					<button class="btn" @click="onSubmit">确认并提交</button>
				</view>
			</view>

		</view>

		<view v-else>
			<view style="background-color: #f4f6f8; padding: 12px 15px">
				<view class="content" :style="{ marginTop: navHeight + 'px' }">
					<view class="one">
						<text class="label">服务对象姓名</text>
						<uni-easyinput input-class="custom-input-class" v-model="Info.infectname"
							placeholder="请输入服务对象姓名" />
					</view>
					<view class="one">
						<text class="label">联系方式</text>
						<uni-easyinput input-class="custom-input-class" type="number" v-model="Info.infectnum"
							placeholder="请输入联系方式" />
					</view>
					<view class="one">
						<text class="label">签字日期</text>
						<uni-datetime-picker :border="false" type="date" placeholder="请选择签字日期" v-model="Info.infectTime"
							disabled />
					</view>
					<view class="one" style="margin-top: 20rpx; border-top: 1px dotted #f4f4f4">
						<text class="label">机构名称</text>
						<uni-easyinput input-class="custom-input-class" v-model="Info.doctorname"
							placeholder="请输入机构名称" />
					</view>
					<view class="one">
						<text class="label">机构联系电话</text>
						<uni-easyinput input-class="custom-input-class" type="number" v-model="Info.doctornum"
							placeholder="请输入机构联系电话" />
					</view>
					<view class="one">
						<text class="label">咨询热线</text>
						<uni-easyinput input-class="custom-input-class" type="number" v-model="Info.consultationNum"
							placeholder="请输入咨询热线" />
					</view>
					<view class="one">
						<text class="label">签字日期</text>
						<uni-datetime-picker :border="false" type="date" placeholder="请选择签字日期" v-model="Info.doctorTime"
							disabled />
					</view>
				</view>
			</view>
			<view class="btn-box" style="display: flex; justify-content: space-between">
				<button class="btn" style="width: 45%" @click="onSign('1')">服务对象签字</button>
				<button class="btn" style="width: 45%" @click="onSign('2')">经办人签字</button>
			</view>
			<view class="btn-box" style="width: 85%; margin: 0 auto" v-if="Info.filebase64">
				<button class="btn" @click="Sign">下一步</button>
			</view>
		</view>

		<uni-popup ref="agreement" type="center" style="border-radius: 26rpx">
			<view class="agreement-height">
				<image class="agree-bg" style="border-radius: 26rpx"
					src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/agree-box.png" mode="widthFix"></image>
				<view class="login-content">
					<view
						style="width: 100%; margin: 0 auto 20rpx; font-size: 40rpx; text-align: center; font-weight: bold">
						性伴动员检测知情同意书</view>
					<view>
						<h4 class="title">第一部分：目的与背景</h4>
						<view style="margin: 20rpx 0">尊敬的_________先生/女士：您好!</view>
						<view class="text">
							感谢您对疾病预防控制工作的支持！为保护您和性伴的健康权益，我们鼓励您在自愿、安全的前提下告知性伴潜在感染风险，并动员其进行HIV自检。本知情同意书将说明您的权利、责任及支持措施，请仔细阅读后确认选择。
						</view>
						<view class="text">
							本项目所指的性伴是指在6个月内与您发生过阴道性交、肛交、口交（存在体液交换风险）的性行为的人。
						</view>
						<h4 class="title">第二部分：您的权利与责任</h4>
						<view class="text">1.自愿原则：您有权自主决定是否告知性伴您的健康状况及动员其检测，我们不会强制要求。若选择告知，我们将提供安全、隐私保护的支持服务。</view>
						<view class="text">2.隐私保护：您的个人信息（如姓名、联系方式）及健康状态将严格保密，未经您书面同意，不会向任何人（包括性伴）泄露。</view>
						<view class="text">3.告知方式建议：自主告知：您可直接联系性伴，建议采用安全方式（如面对面沟通、加密通讯工具）。</view>
						<h4 class="title">第三部分：可能的获益</h4>
						<view class="text">
							1.如果您的密切接触者参加了本次检测并知晓结果为阴性，一方面可以增加您们之间的信任度和亲密感。另一方面也能及早在与其发生危险行为的时候采取必要的防护措施防止疾病的传播，保护对方免受感染；
						</view>
						<view class="text">
							2.如果您的密切接触者感染了HIV，可以让他及早的接受抗病毒治疗和关怀，延长生命、提高生命质量。同时也采取相应的防护措施防止疾病交叉感染，控制疾病进程。
						</view>
						<h4 class="title">第四部分：动员性伴检测的支持措施</h4>
						<view class="text">
							1.检测资源提供：您可向性伴提供以下免费/保密检测途径： 
							智慧化自检：智慧化HIV自检试剂盒（附使用说明及结果解读指南）。提供检测咨询热线：________（如自检指导、窗口期解释）。
						</view>
						<view class="text">2.后续服务：若性伴检测阳性，可协助其快速转介至抗病毒治疗服务。为您提供心理支持或法律咨询。</view>
						<h4 class="title">第五部分：知情确认与选择</h4>
						<view>请您确认以下内容：</view>
						<view class="text">1.我理解告知性伴的意义，并自愿选择是否动员其检测。</view>
						<view class="text">2.我已知晓隐私保护措施，同意机构在授权范围内提供必要协助。</view>
						<h4 class="title">注意事项</h4>
						<view class="text">1. 避免在公开场合或情绪冲突时进行告知。</view>
						<view class="text">2. 本流程遵循《艾滋病防治条例》，禁止任何形式的强迫或歧视。</view>
					</view>
					<view class="agreement-btn-wrap">
						<button class="refuse-btn" @click="onRefuse">拒绝</button>
						<button id="agree-btn" class="ok-btn" @click="handleAgreePrivacyAuthorization"
							open-type="agreePrivacyAuthorization">同意并签字</button>
					</view>
				</view>
			</view>
		</uni-popup>

		<uni-popup ref="popup" type="center" style="border-radius: 26rpx">
			<view style="width: 100%; height: 700rpx">
				<Signature ref="sig" v-model="sign"></Signature>
			</view>
		</uni-popup>

		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" title="添加" v-model="deviceno" placeholder="请输入单个设备编号"
				@confirm="confirm" maxlength="13"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		pathToBase64,
		base64ToPath
	} from 'image-tools';
	import {
		FindLoginUser,
		addSeed_Volunteer,
		FindByUser,
		ConvertCoordinate
	} from '../../utils/api.js';
	import uuid from '@/js_sdk/com-ls-utils/components/ls-utils/index.js';
	import Signature from '@/components/sin-signature/sin-signature.vue';
	import NanchangQuestionnaire from '@/components/NanchangQuestionnaire/index.vue';
	export default {
		data() {
			return {
				subForm: null,
				addressData: "",
				statusBarHeight: '',
				navHeight: '',
				currentDate: new Date().toISOString().split('T')[0],
				show: true,
				TypeHide: true,
				// show: false,
				sign: '',
				AddressArr: [{
					address: '',
					latitude: '',
					longitude: '',
					categor: ''
				}],
				Addressmap: [{
						value: '商业性KTV(含夜总会,歌舞厅)',
						text: '商业性KTV(含夜总会,歌舞厅)'
					},
					{
						value: '洗浴中心',
						text: '洗浴中心'
					},
					{
						value: '酒吧',
						text: '酒吧'
					},
					{
						value: '按摩店（含发廊）',
						text: '按摩店（含发廊）'
					},
					{
						value: '酒店',
						text: '酒店'
					},
					{
						value: '街头场所',
						text: '街头场所'
					},
					{
						value: '出租屋/公寓',
						text: '出租屋/公寓'
					},
					{
						value: '其他',
						text: '其他'
					}
				],
				Info: {
					// NumCode: '',
					Sex: '',
					Age: null,
					DiagnoseTime: '',
					ObtainTime: null,
					ObtainNum: null,
					DeviceNo: '',
					Inclination: '',
					UnprotectAction: '',
					DangerAction: '',
					InfectIllness: '',
					InfectionMode: '',
					SexQuantity: null,
					FirstCD4: '',
					FirstVL: '',
					NewResult: '',
					UserId: null,
					filebase64: '',
					doctorfilebase64: '',
					infectname: '',
					infectnum: '',
					doctorname: '',
					doctornum: '',
					consultationNum: '',
					infectTime: new Date().toISOString().split('T')[0],
					doctorTime: new Date().toISOString().split('T')[0]
				},
				wbhOptions: [{
						text: '是',
						value: '是'
					},
					{
						text: '否',
						value: '否'
					}
				],
				syOptions: [{
						text: '是',
						value: '是'
					},
					{
						text: '否',
						value: '否'
					}
				],
				cbOptions: [{
						text: '是',
						value: '是'
					},
					{
						text: '否',
						value: '否'
					}
				],
				tgOptions: [{
						text: '是',
						value: '是'
					},
					{
						text: '否',
						value: '否'
					}
				],
				sex: [{
						text: '男',
						value: '男'
					},
					{
						text: '女',
						value: '女'
					}
				],
				resOptions: [{
						text: '新发',
						value: '新发'
					},
					{
						text: '既往',
						value: '既往'
					},
					{
						text: '未检测',
						value: '未检测'
					}
				],
				age: Array.from({
						length: 100
					},
					(_, i) => ({
						text: `${i + 1}岁`,
						value: i + 1
					})
				),
				grtj: [{
						text: '同性',
						value: '同性'
					},
					{
						text: '异性',
						value: '异性'
					},
					{
						text: '注射吸毒',
						value: '注射吸毒'
					},
					{
						text: '输血',
						value: '输血'
					},
					{
						text: '母婴',
						value: '母婴'
					}
				],
				penSize: 5,
				content: '知情同意书',
				istrue: false,
				type: '',
				nextShow: false,
				deviceno: '',
				deviceList: [],
			};
		},
		components: {
			Signature,
			NanchangQuestionnaire
		},
		mounted() {
			this.$refs.agreement.open('center');
		},
		onShow() {},
		onLoad(op) {
			this.FindLoginUser();
			var that = this;
			//获取手机系统的信息（在这主要是获取状态栏和胶囊的高度）
			uni.getSystemInfo({
				success: (e) => {
					// this.compareVersion(e.SDKVersion, '2.5.0')
					let statusBar = 0;
					let customBar = 0;
					// #ifdef MP
					statusBar = e.statusBarHeight;
					customBar = e.statusBarHeight + 45;
					if (e.platform === 'android') {
						// this.$store.commit('SET_SYSTEM_IOSANDROID', false)
						customBar = e.statusBarHeight + 50;
					}
					// #endif
					// #ifdef MP-WEIXIN
					statusBar = e.statusBarHeight;
					// @ts-ignore
					const custom = wx.getMenuButtonBoundingClientRect();
					customBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif

					// #ifdef APP-PLUS
					console.log('app-plus', e);
					statusBar = e.statusBarHeight;
					customBar = e.statusBarHeight + 45;
					// #endif

					// #ifdef H5
					statusBar = 0;
					customBar = e.statusBarHeight + 45;
					// #endif

					// 这里你可以自己决定存放方式，建议放在store中，因为store是实时变化的
					this.statusBarHeight = statusBar;
					this.navHeight = customBar;
				}
			});
			//获取当前定位信息
			this.getLocation()
		},
		onNavigationBarButtonTap(event) {
			uni.navigateTo({
				url: '/pages/agree/agree'
			});
		},
		computed: {
			devNum() {
				return this.deviceList.length;
			}
		},
		methods: {
			subWenjuanEven(even) {
				console.log('执行了');
				this.subForm = even
				this.TypeHide = false
				console.log('触发页面改变');
			},
			// 新增一组输入框和下拉框
			addAddress() {
				this.AddressArr.push({
					address: '',
					latitude: '',
					longitude: '',
					categor: ''
				});
			},
			// 删除指定地址项
			removeAddress(index) {
				uni.showModal({
					title: '确认删除',
					content: '您确定要删除这个地址吗？',
					success: (res) => {
						if (res.confirm) {
							// 用户点击确认删除
							if (this.AddressArr.length > 1) {
								this.AddressArr.splice(index, 1);
								uni.showToast({
									icon: 'success',
									title: '地址已删除',
									duration: 1500
								});
							} else {
								uni.showToast({
									icon: 'none',
									duration: 2000,
									title: '至少保留一项'
								});
							}
						} else if (res.cancel) {
							// 用户点击取消
							console.log('用户取消了删除');
						}
					}
				});
			},
			// 用户选择地址地址
			chooseLocation(index) {
				uni.chooseLocation({
					success: (res) => {
						// res 包含了选择的地址信息
						console.log(res);
						// this.location = {
						// 	address: res.name,
						// 	latitude: res.latitude,
						// 	longitude: res.longitude
						// };
						this.$set(this.AddressArr, index, {
							...this.AddressArr[index],
							latitude: res.latitude + '',
							longitude: res.longitude + '',
							address: res.name
						});
						console.log('当前AddressArr', this.AddressArr);
					},
					fail: (err) => {
						console.log('选择位置失败:', err);
					}
				});
			},
			async FindLoginUser() {
				const res = await FindLoginUser();
				console.log(res.data);
				this.Info.UserId = res.data.userid;
				this.watermarkText = res.data.admininfo.name;
			},
			back() {
				uni.navigateBack();
			},
			addOne() {
				this.$refs.inputDialog.open();
			},
			confirm(e) {
				console.log(e);
				if (e.includes('JNA') && e.length == 13) {
					if (this.deviceList.includes(e)) {
						uni.showToast({
							icon: 'none',
							duration: 2000,
							title: '该设备编号已存在'
						});
					} else {
						this.FindByUser(e);
						// this.deviceList.push(e)
					}
				} else {
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: '请输入正确的设备编号'
					});
				}
			},
			removeOne(one) {
				const list = this.deviceList.filter((item) => item !== one);
				this.deviceList = list;
			},
			skip() {
				uni.navigateTo({
					url: '/page-defense/Commercial_VolunteerLst/Commercial_VolunteerLst'
				});
			},
			change(e) {
				console.log(e);
				if (e.detail.value == '是') {
					this.istrue = true;
				} else {
					this.istrue = false;
				}
			},
			verify(num) {
				const regex = /^1[3-9]\d{9}$/;
				if (regex.test(num)) {} else {
					uni.showToast({
						title: '手机号格式错误',
						icon: 'error'
					});
				}
			},
			sys() {
				var that = this;
				uni.scanCode({
					success: function(res) {
						console.log(res);
						if (res.result.includes('JNA')) {
							if (that.deviceList.length >= 3) {
								uni.showToast({
									icon: 'none',
									duration: 2000,
									title: '最多下发三条设备'
								});
								return
							}
							// 判断扫的码是否正确
							if (res.result.length == 13) {
								// 条形码
								if (that.deviceList.includes(res.result)) {
									uni.showToast({
										icon: 'none',
										duration: 2000,
										title: '该设备编号已存在'
									});
								} else {
									that.FindByUser(res.result);
								}
							} else {
								// 二维码
								if (that.deviceList.includes(res.result.split(',')[1])) {
									uni.showToast({
										icon: 'none',
										duration: 2000,
										title: '该设备编号已存在'
									});
								} else {
									that.FindByUser(res.result.split(',')[1]);
								}
							}
						} else {
							uni.showToast({
								title: '请扫描正确的条形码或二维码',
								icon: 'none'
							});
						}
					}
				});
			},
			FindByUser(val) {
				FindByUser(val).then((res) => {
					if (res.code == 200) {
						if (res.data == 0) {
							uni.showToast({
								title: res.message,
								icon: 'none',
								duration: 2000
							});
						} else if (res.data == 1) {
							this.deviceList.push(val);
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none',
								duration: 2000
							});
						}
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
					}
					console.log(res);
				});
			},
			CreateSeed() {
				if (this.Info.Inclination == '是') {} else {
					this.deviceList = [];
				}

				// this.add_Info.phone = this.subForm.phone
				let arrData = []
				arrData.push(this.addressData)
				this.subForm.items[1].optionIds = arrData
				this.Info.QuestionnaireOption = this.subForm.items
				addSeed_Volunteer(this.Info)
					.then((res) => {
						console.log(res);
						if (res.code == 200) {
							uni.hideLoading();
							// this.$refs.popup.close('center')
							uni.showToast({
								title: '新增成功',
								duration: 2000
							});
							(this.AddressArr = [{
								address: '',
								latitude: '',
								longitude: '',
								categor: ''
							}]),
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/module/index'
								});
							}, 2000);
						} else if (res.code == 400) {
							uni.showToast({
								icon: 'none',
								title: '请仔细检查填写信息是否有误',
								duration: 2000
							});
						} else if (res.code == 805) {
							uni.showToast({
								icon: 'none',
								title: res.message,
								duration: 2000
							});
						} else {
							uni.showToast({
								icon: 'none',
								title: res.message,
								duration: 2000
							});
						}
					})
					.catch((err) => {
						console.log(err);
						uni.showToast({
							icon: 'none',
							title: '请仔细检查填写信息是否有误',
							duration: 2000
						});
					});
			},
			Sign() {
				this.show = false;
				// this.$refs.agreement.open('center');
			},
			onRefuse() {
				this.$refs.agreement.close();
				uni.switchTab({
					url: '/pages/module/index'
				});
			},
			handleAgreePrivacyAuthorization() {
				this.$refs.agreement.close();
				// this.$refs.popup.open('center')
				// this.show = false
			},
			async onSign(type) {
				this.$refs.popup.open('center');
				let sign = await this.$refs.sig.getSyncSignature();
				console.log('签字', sign);
				// this.$refs.popup.close('center')
				if (sign && type == '1') {
					this.Info.filebase64 = sign;
					this.$refs.popup.close('center');
				} else if (sign && type == '2') {
					this.Info.doctorfilebase64 = sign;
					this.$refs.popup.close('center');
				} else {
					this.$refs.popup.close('center');
				}

				if (type == '1') {
					this.type = '1';
				} else {
					this.type = '2';
				}
			},
			onSubmit() {
				console.log('当前cd4', this.Info.FirstCD4);
				// 获取需要验证的三项
				let {
					FirstCD4,
					FirstVL,
					SexQuantity
				} = this.Info;

				// 检查每一项是否为数字，并给出具体提示
				if (isNaN(FirstCD4)) {
					uni.showToast({
						title: '首次CD4必须填写数字',
						icon: 'error',
						duration: 2000
					});
					return;
				}

				if (isNaN(FirstVL)) {
					uni.showToast({
						title: '首次病毒载量必须填写数字',
						icon: 'error',
						duration: 2000
					});
					return;
				}

				if (isNaN(SexQuantity)) {
					uni.showToast({
						title: '性伴数必须填写数字',
						icon: 'error',
						duration: 2000
					});
					return;
				}


				var that = this;
				if (!that.Info.Age) {
					that.Info.Age = 0;
				}
				if (!that.Info.SexQuantity) {
					that.Info.SexQuantity = 0;
				}
				uni.showModal({
					title: '提示',
					content: '确认并提交',
					success: function(res) {
						uni.showLoading({
							title: '新增中...'
						});
						if (res.confirm) {
							that.Info.prostitutemsgaddresses = that.AddressArr;
							if (that.Info.Inclination == '是' || that.Info.Inclination == '否') {
								if (that.Info.Inclination == '是') {
									that.Info.DeviceNo = that.deviceList.toString();
									that.Info.ObtainNum = that.devNum;
									if (that.Info.Inclination && that.Info.ObtainTime && that.Info.DeviceNo &&
										that.Info.ObtainNum) {
										that.CreateSeed();
									} else {
										uni.showToast({
											title: '请输入必填项',
											icon: 'none',
											duration: 2000
										});
									}
								} else {
									that.deviceList = [];
									that.CreateSeed();
								}
							} else {
								uni.showToast({
									title: '请填写必填项',
									icon: 'error',
									duration: 2000
								});
							}
						} else if (res.cancel) {
							uni.hideLoading();
							console.log('用户点击取消');
						}
					}
				});
			},
			//获取当前位置
			getLocation(tag) {
				uni.getLocation({
					type: 'wgs84',
					success: async (res) => {
						//res.longitude,res.latitude分别为当前经度，纬度
						ConvertCoordinate({
							Locations: [res.longitude, res.latitude].join(',')
						}).then((res) => {
							if (res.code === 200) {
								console.log('定位返回', res.data.regeocode);
								this.addressData = res.data.regeocode.formatted_address
								// const { province, city, district, township } = res.data.regeocode.addresscomponent;
								// const address = res.data.regeocode.formatted_address;
								// this.$store.commit('$uStore', {
								// 	name: 'vx_city',
								// 	value: {
								// 		province,
								// 		city,
								// 		district,
								// 		township,
								// 		address
								// 	}
								// });
								// console.log('当前省份', this.$store.state.vx_city.province);
								// this.gps = true;
								// console.log(this.gps);
							}
						});
					},
					fail: (err) => {
						console.log(err);
						// this.gps = false;
						// uni.showModal({
						// 	title: '提示',
						// 	content: '使用本设备时，请开启手机定位！',
						// 	showCancel: false,
						// 	success: (res) => {
						// 		if (res.confirm) {
						// 			console.log('用户点击确定');
						// 			uni.openSetting({
						// 				success: function (res) {
						// 					// scope.bluetooth
						// 					// 在成功回调中判断用户是否已开启位置权限，并进行相应处理
						// 					if (res.authSetting['scope.userLocation']) {
						// 						// 用户已开启位置权限，可以重新调用 uni.getLocation 获取位置信息
						// 						console.log('调用');
						// 					}
						// 				}
						// 			});
						// 		}
						// 	}
						// });
					}
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.page {
		// padding: 50rpx;
		height: 100vh;
		position: relative;
		background-color: #f4f4f4;

		.nav-style {
			background-image: url('https://www.shlxkj.info:10010/%E5%81%A5%E5%BA%B7%E6%A1%A3%E6%A1%88/zsafimg/bgimg.png');
			background-size: cover;
			background-repeat: no-repeat;
			position: fixed;
			top: 0;
			right: 0;
			left: 0;
			z-index: 1000;
			display: flex;
			padding-left: 23rpx;
			align-items: center;
			justify-content: center;

			image {
				position: absolute;
				left: 15px;
			}
		}

		.content {
			background-color: #fff;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			padding: 20rpx;

			.one {
				height: 84rpx;
				padding: 10rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 1px solid #f4f4f4;

				.label {
					color: #222222;
					font-weight: 500;
					font-size: 28rpx;
					width: 250rpx;
				}
			}

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.btn-box {
			background-color: #f4f4f4;
			padding: 40rpx;

			.btn {
				// width: 95%;
				height: 105rpx;
				// margin: 100rpx auto 0;
				color: #ffffff;
				font-weight: 500;
				font-size: 40rpx;
				background: linear-gradient(90deg, #a4edf1 0%, #00aeff 100%);
				box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(14, 98, 122, 0.15);
				border-radius: 12rpx 12rpx 12rpx 12rpx;
			}

			.btn:nth-child(2) {
				background: linear-gradient(90deg, #00aeff 0%, #a4edf1 100%);
			}
		}

		.other {
			display: flex;
			justify-content: space-between;

			image {
				width: 60rpx;
				height: 60rpx;
			}

			.left {
				flex: 1;
			}
		}

		.agreement-height {
			width: 615rpx;
			height: 70vh;
			margin: 0 auto;
			border-radius: 26rpx;
			background-color: #ffffff;
			position: relative;

			.fixed {
				position: fixed;
				left: 580rpx;
				top: 40vh;
				transform: rotate(90deg);
				// writing-mode: vertical-lr;
			}

			.agree-bg {
				width: 615rpx;
				position: absolute;
				z-index: 0;
			}

			.login-content {
				width: 515rpx;
				position: absolute;
				padding: 60rpx 50rpx 0;
				height: calc(100% - 100rpx);
				overflow-y: scroll;
			}

			.title {
				margin: 30rpx 0;
			}

			.text {
				text-indent: 2rem;
			}

			.agreement-btn-wrap {
				background-color: #ffffff;
				padding-top: 20rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.ok-btn {
					width: 250rpx;
					height: 85rpx;
					line-height: 85rpx;
					border-radius: 15rpx;
					text-align: center;
					font-size: 31rpx;
					font-weight: 400;
					color: #ffffff;
					background: linear-gradient(90deg, #a4edf1 0%, #00aeff 100%);
					box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(14, 98, 122, 0.15);
				}

				.refuse-btn {
					width: 250rpx;
					height: 85rpx;
					line-height: 85rpx;
					font-size: 31rpx;
					font-weight: 400;
					color: #333333;
					background: #ebebed;
					text-align: center;
					border-radius: 15rpx;
				}
			}

			.popup_info {
				margin: auto;
				width: 80%;
				padding-top: 60rpx;
			}

			.sign {
				border-radius: 12rpx;
			}

			.btn2 {
				background: linear-gradient(#639cff, #1e64e0);
				margin-top: 20rpx;
				color: #fff;
			}
		}

		.solid {
			border-bottom: 1px dashed gray;
			margin-bottom: 30rpx;
		}

		// 输入框
		// ::v-deep .uni-easyinput__content {
		// 	border-radius: 12rpx 12rpx 12rpx 12rpx;
		// }

		// ::v-deep .uni-easyinput__content-input {
		// 	height: 84rpx;
		// 	text-align: center;
		// }

		// ::v-deep .is-input-border {
		// 	border: none;
		// }

		// ::v-deep .uni-easyinput__placeholder-class {
		// 	text-align: center;
		// }

		::v-deep .content-clear-icon {
			display: none;
		}

		// 时间选择器
		::v-deep .uni-date-editor {
			text-align: right;
		}

		::v-deep.uni-date-x .uni-date-single {}

		::v-deep .icon-calendar {
			position: absolute;
			right: 0 !important;
		}

		::v-deep .uni-date__icon-clear {
			display: none;
		}

		::v-deep .uni-date__x-input {
			margin-right: 50rpx;
		}

		// 下拉框

		::v-deep .selected-area,
		.placeholder,
		.selected-list {
			justify-content: flex-end !important;
			text-align: right !important;
			font-size: 14px;
		}

		::v-deep .input-value-border {
			border: none;
		}

		// 单选框
		::v-deep .checklist-group {
			justify-content: flex-end;
		}

		::v-deep .placeholder {
			text-align: right;
		}

		::v-deep .input-value-border {
			background-color: #fff;
		}

		::v-deep .uni-data-tree {
			width: 80%;
			margin-top: 15rpx;
			margin-bottom: 15rpx;
		}

		::v-deep .selected-list {
			display: block;
			text-align: center
		}

		.uni-forms-item {
			display: flex;
			align-items: center;
		}
	}

	//
</style>